﻿
Imports System.Threading

Public Module _shared
    Public Function create_node_property_key(ByVal id As Int64, ByVal name As String, ByVal type As String) As String
        Return strcat(constants.properties.prefix, id, constants.key_separator, name, constants.key_separator, type)
    End Function

    Public Function create_blob_key(ByVal id As Int64) As String
        Return strcat(constants.blobs.prefix, id)
    End Function

    Public read_timeout_ms As Int64 = secondsToMilliseconds(10)
    Public write_timeout_ms As Int64 = secondsToMilliseconds(10)
    Public read_retry_wait_ms As Int64 = secondsToMilliseconds(5)
    Public write_retry_wait_ms As Int64 = secondsToMilliseconds(5)
    Public write_back_interval_ms As Int64 = secondsToMilliseconds(10)
    Public max_pending_blob_count As Int64 = 1024

    Public Class constants
        Public Class properties
            Public Const property_list_name As String = "pl"
            Public Const prefix As String = character._N + key_separator
        End Class

        Public Class blobs
            Public Const prefix As String = character._B + key_separator
        End Class

        Public Const path_separator As Char = character.leftSlash
        Public Const key_separator As Char = character.dot
    End Class
End Module

Friend Class next_id
    Private n As Int64 = 0

    Public Sub New()
        n = Now.hires_ticks()
    End Sub

    Public Function [next]() As Int64
        Return Interlocked.Increment(n)
    End Function
End Class
